package fallingGame;

import java.util.Timer;
import java.util.TimerTask;

/**
 * <p>
 * Title: PlayerScore
 * </p>
 * <p>
 * Description: CS 343 Course Project PlayerScore is a simple class that
 * utilizes java.util.Timer to increment the score by 1 every second.
 * </p>
 * 
 * @author Nathanial Howard, Joe Costello, Dustin Schwingle, Jared Potter
 * @email nathanial.howard@my.uwrf.edu, anthony.costello@my.uwrf.edu,
 *        dustin.schwingle@my.uwrf.edu, jared.potter@my.uwrf.edu
 * @date December 01, 2011
 * @team Group 2
 */
public class PlayerScore {

	private Timer timer;
	private RemindTask task;
	private int playerScore = 0;

	/**
	 * PlayerScore() creates a new PlayerScore
	 * 
	 * @ensure new timer and new task are created the schedule for the timer is
	 *         created
	 */
	public PlayerScore() {
		timer = new Timer();
		task = new RemindTask();
		timer.schedule(task, 0, // initial delay
				100); // subsequent rate
	}

	/**
	 * add(int score) adds a designated amount to the playerScore
	 * 
	 * @require score >= 0
	 * 
	 * @ensure playerScore >= 0 playerScore += score
	 */
	public void add(int score) {
		playerScore += score;
	}

	/**
	 * getTimer() returns the timer
	 * 
	 * @return timer
	 * @ensure timer will be returned
	 */
	public Timer getTimer() {
		return timer;
	}

	/**
	 * getTask() returns the task
	 * 
	 * @return task
	 * @ensure task will be returned
	 */
	public RemindTask getTask() {
		return task;
	}

	public class RemindTask extends TimerTask {

		/**
		 * run() runs the timer and performs a task this task adds 1 to the
		 * player score
		 * 
		 * @ensure playerScore += 1
		 */
		public void run() {
			playerScore++;
		}

		/**
		 * getPlayerScore() returns the playerScore
		 * 
		 * @return playerScore
		 * @ensure playerScore will be returned
		 */
		public int getPlayerScore() {
			return playerScore;
		}
	}

}
